/**
 * @param {number[]} nums
 * @return {number[]}
 */


var exchange = function (nums) {
    let len = nums.length
    if (len <= 1) {
        return nums
    }
    let low = 0
    let fast = 1
    while (low < len && fast < len) {
        // low找偶数
        while (low < len && nums[low] % 2 !== 0) {
            low++
        }
        // fast找奇数
        while (fast < len && nums[fast] % 2 === 0) {
            fast++
        }
        if (low < len && fast < len && low < fast) {
            [nums[low], nums[fast]] = [nums[fast], nums[low]]
        } else {
            [low, fast] = [fast, low]
        }
    }
    return nums
};